package dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import entity.Category;

public interface CategoryDao {

	@Select("select * from t_cate where pid is null")
	public List<Category> findparents();
	
	@Insert("insert into t_cate(cname,des) values(#{cname},#{des})")
	public Integer insertcate(Category cate);
	
	@Select("select * from t_cate where pid=#{cid}")
	public List<Category> findchildren(Integer cid);
	
	@Insert("insert into t_cate(cname,des,pid) values(#{cname},#{des},#{parent.cid})")
	public Integer inserttwocate(Category cate);
	
	@Select("select * from t_cate where cid=#{cid}")
	public Category findCategoryById(Integer cid);
	
	@Update("update t_cate set cname=#{cname},des=#{des} where cid=#{cid}")
	public Integer updatefathercate(Category cate);
	
	@Delete("delete from t_cate where pid=#{pid}")
	public Integer deletechildrencate(Integer pid);
	
	@Delete("delete from t_cate where cid=#{cid}")
	public Integer deletefathercatebyid(Integer cid);
	
	
	public Category findchildcatebyid(Integer cid);
	
	@Update("update t_cate set cname=#{cname},des=#{des},pid=#{parent.cid} where cid=#{cid}")
	public Integer updatechildcate(Category cate);
	
	@Delete("delete from t_cate where cid=#{cid}")
	public Integer deletechildcateById(Integer cid);
}
